package com.example.smartg.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.smartg.ManagerLoginActivity;
import com.example.smartg.R;
import com.example.smartg.SmartGMainActivity;
import com.example.smartg.SpUtils;

import javax.security.auth.callback.Callback;

import androidx.appcompat.app.AlertDialog;

public class SuperUserDialogUtil {
    public static void auth(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.superuser_password, null);
        Button btn_sure = (Button) v.findViewById(R.id.dialog_btn_sure);
        Button btn_cancel = (Button) v.findViewById(R.id.dialog_btn_cancel);
        //builer.setView(v);//这里如果使用builer.setView(v)，自定义布局只会覆盖title和button之间的那部分
        final Dialog dialog = new Dialog(context,R.style.custrom_dialog);
        dialog.show();
        dialog.getWindow().setContentView(v);//自定义布局应该在这里添加，要在dialog.show()的后面
        dialog.getWindow().setGravity(Gravity.CENTER);//可以设置显示的位置
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v2) {
                EditText ps = (EditText) v.findViewById(R.id.superuser_ps);
                if(ps.getText().toString().equals("07560756")){
                    dialog.dismiss();
                    ManagerLoginActivity ma = (ManagerLoginActivity) context;
                    ma.exitAPP();
                }else {
                    ToastUtil.error(context,"密码错误！");
                }
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
    }
}
